package com.itfreer.data.general;

import com.itfreer.data.general.domain.IDomain;
import com.itfreer.utils.StringUtils;

/**
 * 定义字段信息类
 */
public class Field {

	/**
	 * 字段名称
	 */
	private String fieldName;

	/**
	 * 字段ID(排序号)
	 */
	private int fieldID;

	/**
	 * 字段别名
	 */
	private String fieldAliasName;

	/**
	 * 字段类型
	 */
	private GlobalDataType dataType;

	/**
	 * 是否是自动增值列
	 */
	private boolean isAuto;

	/**
	 * 是否是主键
	 */
	private boolean isKey;

	/**
	 * 字段是否必需(注册时可忽略)
	 */
	private boolean isEssential;

	/**
	 * 长度
	 */
	private int maxLen;

	/**
	 * 小数位长度
	 */
	private int decimaldigits;

	/**
	 * 是否可以为空
	 */
	private boolean allowNull;

	/**
	 * 默认值
	 */
	private String defaultValue;

	/**
	 * 是否显示
	 */
	private boolean canShow;

	/**
	 * 是否只读
	 */
	private boolean readOnly;

	/**
	 * 唯一键分组
	 */
	private String uniqueGroup;

	/**
	 * 字典域
	 */
	private String domainTable;

	/**
	 * 字典域条件
	 */
	private String domainName;

	/**
	 * 字段单位
	 */
	private String unit;

	/**
	 * 字段分组
	 */
	private String group;

	/**
	 * 域值处理对象
	 */
	private IDomain domain;

	public String getFieldName() {
		return fieldName;
	}

	public void setFieldName(String fieldName) {
		this.fieldName = fieldName;
	}

	public int getFieldID() {
		return fieldID;
	}

	public void setFieldID(int fieldID) {
		this.fieldID = fieldID;
	}

	public String getFieldAliasName() {
		if (StringUtils.IsNullOrSpace(fieldAliasName))
			return fieldName;
		else
			return fieldAliasName;
	}

	public void setFieldAliasName(String value) {
		fieldAliasName = value;
	}

	public GlobalDataType getDataType() {
		return dataType;
	}

	public void setDataType(GlobalDataType dataType) {
		this.dataType = dataType;
	}

	public boolean getIsAuto() {
		return isAuto;
	}

	public void setIsAuto(boolean value) {
		isAuto = value;
	}

	public boolean getIsKey() {
		return isKey;
	}

	public void setIsKey(boolean isKey) {
		this.isKey = isKey;
	}

	public int getMaxLen() {
		return maxLen;
	}

	public void setMaxLen(int maxLen) {
		this.maxLen = maxLen;
	}

	public int getDecimaldigits() {
		return decimaldigits;
	}

	public void setDecimaldigits(int decimaldigits) {
		this.decimaldigits = decimaldigits;
	}

	public boolean getAllowNull() {
		return allowNull;
	}

	public void setAllowNull(boolean allowNull) {
		this.allowNull = allowNull;
	}

	public String getDefaultValue() {
		return defaultValue;
	}

	public void setDefaultValue(String defaultValue) {
		this.defaultValue = defaultValue;
	}

	public Boolean getCanShow() {
		return canShow;
	}

	public void setCanShow(boolean canShow) {
		this.canShow = canShow;
	}

	public Boolean getReadOnly() {
		return readOnly;
	}

	public void setReadOnly(boolean readOnly) {
		this.readOnly = readOnly;
	}

	public String getUniqueGroup() {
		return uniqueGroup;
	}

	public void setUniqueGroup(String uniqueGroup) {
		this.uniqueGroup = uniqueGroup;
	}

	public String getDomainTable() {
		return domainTable;
	}

	public void setDomainTable(String value) {
		domainTable = value;
	}

	public String getDomainName() {
		return domainName;
	}

	public void setDomainName(String value) {
		domainName = value;
	}

	public String getUnit() {
		return unit;
	}

	public void setUnit(String value) {
		unit = value;
	}

	public String getGroup() {
		return group;
	}

	public void setGroup(String group) {
		this.group = group;
	}

	public boolean getIsEssential() {
		return isEssential;
	}

	public void setIsEssential(boolean value) {
		isEssential = value;
	}

	public boolean getHasDomain() {
		return (domain != null || !StringUtils.IsNullOrSpace(this.domainName));
	}

	public IDomain getDomain() {
		if (domain == null && this.getHasDomain()) {
			ITableFactory tableFactory = TableFactoryClass.install;
			domain = tableFactory.openDomain(this.domainTable, this.domainName);
		}
		return domain;
	}

	public void setDomain(IDomain domain) {
		this.domain = domain;
	}
}